﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcBHXH.Common;

namespace MvcBHXH.Models
{
    class NguoiSudungModel
    {
        private DataClassesBHYTTNDataContext context;
        public NguoiSudungModel() 
        {
            context = Util.CreateInstance().DataContext();
        }

        public List<NguoiSudungModel> GetNguoiSudungModel()
        {
            var NguoiSudung = from fc in context.tbl_NguoiSuDungs
                              select new 
                              {
                                  fc.Ma_NSD,
                                  fc.Ten_NSD,
                                  fc.MatKhau,
                                  fc.Email,
                                  fc.Ma_Tinh,
                                  fc.Ma_Huyen,
                                  fc.Ma_DonViBH,
                                  fc.Loai_NSD,
                                  fc.TinhTrang,
                                  fc.GhiChu,
                                  fc.NgayTaoMoi,
                                  fc.NgayCapNhat,
                              };
            List<NguoiSudungModel> listNguoiSudungModel = new List<NguoiSudungModel>();
            NguoiSudungModel objNguoiSudungModel;
            foreach (var item in NguoiSudung)
            {
                objNguoiSudungModel = new NguoiSudungModel();
                objNguoiSudungModel.MaNSD = item.Ma_NSD;
                objNguoiSudungModel.TenNSD = item.Ten_NSD;
                objNguoiSudungModel.MatKhau = item.MatKhau;
                objNguoiSudungModel.Email = item.Email;
                objNguoiSudungModel.MaTinh = item.Ma_Tinh;
                objNguoiSudungModel.MaHuyen = item.Ma_Huyen;
                objNguoiSudungModel.MaDonViBH = item.Ma_DonViBH;
                objNguoiSudungModel.LoaiNSD = item.Loai_NSD;
                objNguoiSudungModel.TinhTrang = (int)item.TinhTrang;
                objNguoiSudungModel.GhiChu = item.GhiChu;
                //objNguoiSudungModel.NgayTaoMoi = item.NgayTaoMoi;
                //objNguoiSudungModel.NgayCapNhat = item.NgayCapNhat;

                listNguoiSudungModel.Add(objNguoiSudungModel);
            }
            return listNguoiSudungModel;
        }

        public NguoiSudungModel Authentication(string email, string pass)
        {
            var NguoiSudung = from fc in context.tbl_NguoiSuDungs where fc.Email.Equals(email) && fc.MatKhau.Equals(pass)
                              select new
                              {
                                  fc.Ma_NSD,
                                  fc.Ten_NSD,
                                  fc.MatKhau,
                                  fc.Email,
                                  fc.Ma_Tinh,
                                  fc.Ma_Huyen,
                                  fc.Ma_DonViBH,
                                  fc.Loai_NSD,
                                  fc.TinhTrang,
                                  fc.GhiChu,
                                  fc.NgayTaoMoi,
                                  fc.NgayCapNhat,
                              };

            NguoiSudungModel objNguoiSudungModel;
            foreach (var item in NguoiSudung)
            {
                objNguoiSudungModel = new NguoiSudungModel();
                objNguoiSudungModel.MaNSD = item.Ma_NSD;
                objNguoiSudungModel.TenNSD = item.Ten_NSD;
                objNguoiSudungModel.MatKhau = item.MatKhau;
                objNguoiSudungModel.Email = item.Email;
                objNguoiSudungModel.MaTinh = item.Ma_Tinh;
                objNguoiSudungModel.MaHuyen = item.Ma_Huyen;
                objNguoiSudungModel.MaDonViBH = item.Ma_DonViBH;
                objNguoiSudungModel.LoaiNSD = item.Loai_NSD;
                objNguoiSudungModel.TinhTrang = (int)item.TinhTrang;
                objNguoiSudungModel.GhiChu = item.GhiChu;
                //objNguoiSudungModel.NgayTaoMoi = item.NgayTaoMoi;
                //objNguoiSudungModel.NgayCapNhat = item.NgayCapNhat;

                return objNguoiSudungModel;
            }
            return null;
        }

        private string maNSD;

        public string MaNSD
        {
            get { return maNSD; }
            set { maNSD = value; }
        }
        private string tenNSD;

        public string TenNSD
        {
            get { return tenNSD; }
            set { tenNSD = value; }
        }
        private string matKhau;

        public string MatKhau
        {
            get { return matKhau; }
            set { matKhau = value; }
        }
        private string email;

        public string Email
        {
            get { return email; }
            set { email = value; }
        }
        private string maTinh;

        public string MaTinh
        {
            get { return maTinh; }
            set { maTinh = value; }
        }
        private string maHuyen;

        public string MaHuyen
        {
            get { return maHuyen; }
            set { maHuyen = value; }
        }
        private string maDonViBH;

        public string MaDonViBH
        {
            get { return maDonViBH; }
            set { maDonViBH = value; }
        }
        private string loaiNSD;

        public string LoaiNSD
        {
            get { return loaiNSD; }
            set { loaiNSD = value; }
        }
        private int tinhTrang;

        public int TinhTrang
        {
            get { return tinhTrang; }
            set { tinhTrang = value; }
        }
        private string ghiChu;

        public string GhiChu
        {
            get { return ghiChu; }
            set { ghiChu = value; }
        }
        private DateTime ngayTaoMoi;

        public DateTime NgayTaoMoi
        {
            get { return ngayTaoMoi; }
            set { ngayTaoMoi = value; }
        }
        private DateTime ngayCapNhat;

        public DateTime NgayCapNhat
        {
            get { return ngayCapNhat; }
            set { ngayCapNhat = value; }
        }

    }
}
